#ifndef _HLFS_CLEAN_H_
#define _HLFS_CLEAN_H_

#define MAP_NUM			(256llu)
#define SEG_NUM			(100)
#define STOP			(0)
#define SUSPEND			(1)
#define RUN			(2)
#define WATERLEVEL		(8000)
#define LOG_BUF			(0x0ffffffflu)
#define BIT_SHIFT		(0x0000000000000000llu)
#define SU_LEN			(sizeof(struct segment_usage))
#define BIT_CHECK		(0x0000000000000001llu)

#include <stdint.h>
#include "glib.h"
#include "hlfs.h"

/* segment usage structure for cleaning task */
struct segment_usage {
	uint64_t segno;				
	uint64_t alive_blocks;
	uint64_t alive_log_bitmap[MAP_NUM];
	uint64_t timestamp;
};

/* request structure for write thread */ 
typedef struct w_req {
	char *buf;
	uint64_t size;
	uint64_t pos;
} w_req_t;

/* response structure for write thread */
typedef struct w_res {
	uint32_t err_no;
	uint64_t size;
} w_res_t;

/* some functions for ckeaning task */
uint64_t get_last_inode_addr(struct hlfs_ctrl *ctrl, char *segfile);
struct inode *load_inode(struct hlfs_ctrl *ctrl, char *segfile, uint64_t inode_addr);
uint64_t get_db_addr(struct hlfs_ctrl *ctrl, struct inode *inode, uint64_t db_no);
void load_segment_usage(struct hlfs_ctrl *ctrl);
int add_new(struct hlfs_ctrl *ctrl);
void dump_segment_usage_table(struct hlfs_ctrl *ctrl);
void su_check_task(struct hlfs_ctrl *ctrl);
uint64_t get_storage_address(struct hlfs_ctrl *ctrl, struct inode *inode, uint64_t bno);
char *handle(struct hlfs_ctrl *ctrl, struct segment_usage *su, uint64_t log_idx, uint64_t *buf_size);
void log_dump(struct hlfs_ctrl *ctrl, char *buf, uint64_t buf_size);
gpointer g_async_queue_timeout_pop(struct hlfs_ctrl *ctrl, uint32_t time);
void api_write_rewrite(struct hlfs_ctrl *ctrl, char *write_buf, uint32_t write_len, uint64_t pos);
void write_thread(struct hlfs_ctrl *ctrl);

#endif
